package com.xm.servlet.background.commodity;

import com.google.gson.Gson;
import com.xm.entity.CommodityInsurance;
import com.xm.service.background.CommodityInsuranceService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 新增保险
 * @author 康文程
 * @date 2024-1-18 下午 04:13
 */
@WebServlet("/background/add/commodity/insurance")
public class AddCommodityInsuranceServlet extends HttpServlet {
    private final CommodityInsuranceService service = new CommodityInsuranceService();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String commodityInsuranceJson = req.getParameter("commodityInsurance");
        CommodityInsurance commodityInsurance = new Gson().fromJson(commodityInsuranceJson, CommodityInsurance.class);
        resp.getWriter().print(service.addCommodityInsurance(commodityInsurance));
    }
}
